package leetcode.array;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
 * Created by xinxuchu on 2020/9/10.
 */
public class Question977 {

    static public int[] sortedSquares(int[] A) {

        List<Integer> list = new ArrayList<>();
        for (int a:A) {
            list.add(a*a);
        }
        Collections.sort(list);
        int[] b = new int[A.length];
        for (int i=0;i<b.length;i++){
            b[i] = list.get(i);
        }
        return b;
    }

    static public int[] sortedSquares1(int[] A) {

        int[] new1 = new int[A.length];
        for (int i = 0;i<A.length;i++){
            new1[i] = A[i]*A[i];
        }
        Arrays.sort(new1);
        return new1;
    }

    public static void main(String[] args) {
        Question977 question977 = new Question977();
        System.out.println(Arrays.toString(sortedSquares1(new int[]{1,1,1,2,2,3,3,4,4})));
    }
}
